package com.company.beauty.common.utils;

import com.company.nuwa.common.constants.Headers;
import com.company.nuwa.common.domain.HttpMessageResult;
import com.company.nuwa.common.utils.RequestContextUtil;

/**
 * <p>http message result util</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2023/12/13 15:36
 */
public class HttpMessageResultUtil {

    /**
     * 失败请求，自动填充 header
     *
     * @param code
     * @param message
     * @return
     */
    public static HttpMessageResult<String> failure(int code, String message) {
        return failure(code, message, getHeader());
    }

    /**
     * 失败请求
     *
     * @param code
     * @param message
     * @param header
     * @return
     */
    public static HttpMessageResult<String> failure(int code, String message, HttpMessageResult.Header header) {
        return new HttpMessageResult<>(code, message, null, null, header);
    }

    /**
     * 获取当前请求 header
     *
     * @return
     */
    public static HttpMessageResult.Header getHeader() {
        String traceId = RequestContextUtil.getHeader(Headers.TRACE_ID);
        String uri = RequestContextUtil.getRequestURI();
        return HttpMessageResult.Header.builder(traceId, uri);
    }

}
